package cn.com.web;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liufl E-mail:Huberier@allpyra.com
 * @version 创建时间：2017年7月19日 下午2:51:51 类说明
 */
@EnableAutoConfiguration
@RefreshScope//配置中心参数刷新时也跟着刷新http://localhost:8081/refresh
@RestController
public class TestController {

	Logger log = LoggerFactory.getLogger(this.getClass());

	@Value("${hello}")
    private String hello;//读取cloud配置中心的参数http://localhost:8888/cloud-client-consumer-dev.properties


	@RequestMapping("/test")
	public String hello(HttpServletRequest req) {
		return "Hello " + hello + "!"+getUrl(req);
	}

	private String getUrl(HttpServletRequest req){
		String url=req.getScheme()+"://"+ req.getServerName()+":"+req.getServerPort()+"/"+req.getContextPath();
		return url;
	}
}
